package library.operation;

import library.BookList;
import library.Book;

import java.util.Scanner;

public class ReturnOperation implements IOperation {
    @Override
    public void work(BookList bookList){
        System.out.println("还书");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入要归还的书的编号：");
        int id = scanner.nextInt();
        if (id < 0 || id >= bookList.getSize()){
            System.out.println("输入的编号无效");
            return;
        }
        Book book = bookList.getBook(id);
        if (!book.isBorrowed()){
            System.out.println("该书未被借出，不能归还");
            return;
        }
        book.setBorrowed(false);
        System.out.println("归还成功");
    }
}
